package com.ruoyi.bearing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bearing.domain.ComponentTypes;
import com.ruoyi.bearing.service.IComponentTypesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 元器件类型管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/bearing/types")
public class ComponentTypesController extends BaseController
{
    @Autowired
    private IComponentTypesService componentTypesService;

    /**
     * 查询元器件类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComponentTypes componentTypes)
    {
        startPage();
        List<ComponentTypes> list = componentTypesService.selectComponentTypesList(componentTypes);
        return getDataTable(list);
    }

    /**
     * 导出元器件类型管理列表
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:export')")
    @Log(title = "元器件类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComponentTypes componentTypes)
    {
        List<ComponentTypes> list = componentTypesService.selectComponentTypesList(componentTypes);
        ExcelUtil<ComponentTypes> util = new ExcelUtil<ComponentTypes>(ComponentTypes.class);
        util.exportExcel(response, list, "元器件类型管理数据");
    }

    /**
     * 获取元器件类型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(componentTypesService.selectComponentTypesByTypeId(typeId));
    }

    /**
     * 新增元器件类型管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:add')")
    @Log(title = "元器件类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComponentTypes componentTypes)
    {
        return toAjax(componentTypesService.insertComponentTypes(componentTypes));
    }

    /**
     * 修改元器件类型管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:edit')")
    @Log(title = "元器件类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComponentTypes componentTypes)
    {
        return toAjax(componentTypesService.updateComponentTypes(componentTypes));
    }

    /**
     * 删除元器件类型管理
     */
    @PreAuthorize("@ss.hasPermi('bearing:types:remove')")
    @Log(title = "元器件类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(componentTypesService.deleteComponentTypesByTypeIds(typeIds));
    }
}
